//
//  WaiSongYuYueView.m
//  外卖点餐预约view
//
//  Created by xiaofang wang on 2018/12/8.
//  Copyright © 2018年 zhiyuan. All rights reserved.
//宽高自适应

#import "WaiSongYuYueView.h"
@interface WaiSongYuYueView()
/**1.bgImagView ❌  这是一个UIImageView 请打开用户交互不然死活无法响应点击事件 ⚠️*/
@property (nonatomic, strong) UIImageView *bgImageView;
/**2.外卖点餐文字 + 约30分钟送达 div 添加手势 */
@property (nonatomic, strong) UIView *leftDiv;
/**左按钮点击事件*/
@property (nonatomic, strong) UIButton *leftBtn;
/**2-1外卖点餐labe*/
@property (nonatomic, strong) UILabel *waimaidiancanLb;
/**2-2约30分钟送达*/
@property (nonatomic, strong) UILabel *yue30songdaLb;


/**3.预约点餐 + 预约区号不排队 div 添加手势 */
@property (nonatomic, strong) UIView *rightDiv;
/**右按钮点击事件*/
@property (nonatomic, strong) UIButton *rightBtn;

/**3-1预约点餐lb*/
@property (nonatomic, strong) UILabel *yuyuediancanLb;
/**3-2预约区号不排队lb*/
@property (nonatomic, strong) UILabel *bupaiduiLb;

/**4.左右div数组*/
@property (nonatomic, strong) NSMutableArray *leftRightDivArrM;
/**4-2左边两个view数组*/
@property (nonatomic, strong) NSMutableArray *leftViewArrayM;
/**4-3右边两个view数组*/
@property (nonatomic, strong) NSMutableArray *rightViewArrayM;
@end

@implementation WaiSongYuYueView
#pragma mark - 一 init
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupUI];
    }
    return self;
}
- (void)setupUI {
    
    [self addSubview:self.bgImageView];

    [self.bgImageView addSubview:self.leftDiv];
    [self.bgImageView addSubview:self.rightDiv];
    
    //外送点餐 + 约30分钟送达
    [self.leftDiv addSubview:self.waimaidiancanLb];
    [self.leftDiv addSubview:self.yue30songdaLb];
    
    //预约取餐 + 预约区号不排队
    [self.rightDiv addSubview:self.yuyuediancanLb];
    [self.rightDiv addSubview:self.bupaiduiLb];
    
    
    //等宽高 等间距排列过个控件
    //左右打div数组
    [self.leftRightDivArrM addObject:self.leftDiv];
    [self.leftRightDivArrM addObject:self.rightDiv];
    //左右事件监听按钮数组
   
    
    //左边上下来个view
    [self.leftViewArrayM addObject:self.waimaidiancanLb];
    [self.leftViewArrayM addObject:self.yue30songdaLb];
    
    //右边上下两个view
    [self.rightViewArrayM addObject:self.yuyuediancanLb];
    [self.rightViewArrayM addObject:self.bupaiduiLb];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
//    self.bgImageView.backgroundColor = [UIColor redColor];
    [self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(6);
        make.right.equalTo(self.mas_right).offset(-6);
        make.top.equalTo(self.mas_top);
        make.bottom.equalTo(self.mas_bottom);
    }];
    
    //水平,两个控件等宽
    //参数1:方向 horizontal 水平、vertical 垂直
    //参数2:两个控件的固定间隔 10
    //参数3:第一个控件与边缘的间距
    //参数4:第二个控件与边缘的间距
    [self.leftRightDivArrM mas_distributeViewsAlongAxis:(MASAxisTypeHorizontal) withFixedSpacing:0 leadSpacing:0 tailSpacing:0];
    [self.leftRightDivArrM mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.bgImageView.mas_top);
        make.bottom.equalTo(self.bgImageView.mas_bottom);
    }];
    
    CGFloat tailSpacingVertical = FDHeightScale(26);
    //左边上下等宽
    [self.leftViewArrayM mas_distributeViewsAlongAxis:MASAxisTypeVertical withFixedSpacing:5 leadSpacing:15 tailSpacing:tailSpacingVertical];
    [self.leftViewArrayM mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.leftDiv.mas_left).offset(15);
        make.right.equalTo(self.leftDiv.mas_right);
    }];
    
    //右边上下等宽
    [self.rightViewArrayM mas_distributeViewsAlongAxis:MASAxisTypeVertical withFixedSpacing:5 leadSpacing:15 tailSpacing:tailSpacingVertical];
    [self.rightViewArrayM mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.rightDiv.mas_left).offset(10);
        make.right.equalTo(self.rightDiv.mas_right);
    }];
}

#pragma mark - 二 getter
- (UIImageView *)bgImageView {
    if (!_bgImageView) {
        _bgImageView = [[UIImageView alloc] init];
        _bgImageView.userInteractionEnabled = YES;
        _bgImageView.image = [UIImage imageNamed:@"首页外卖点餐预定图片"];
    }
    return _bgImageView;
}

//!!!!:1.leftDiv
- (UIView *)leftDiv {
    if (!_leftDiv) {
        _leftDiv = [[UIView alloc] init];
        UITapGestureRecognizer *leftTapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickLeftTapGes)];
        [_leftDiv addGestureRecognizer:leftTapGes];
    }
    return _leftDiv;
}

- (UILabel *)waimaidiancanLb {
    if (!_waimaidiancanLb) {
        _waimaidiancanLb = [[UILabel alloc] init];
        _waimaidiancanLb.text = NSLocalizedString(Home_WaiSongDianCan, @"外买点餐");
    }
    return _waimaidiancanLb;
}
- (UILabel *)yue30songdaLb {
    if (!_yue30songdaLb) {
        _yue30songdaLb = [[UILabel alloc] init];
        
        NSString *sdsjStr = @"Delivery in about\n30 minutes";
        if ([NSString rb_ChineseLanguage]) {
            sdsjStr = @"约30分钟送达";
        }
        _yue30songdaLb.text = sdsjStr;
        
        _yue30songdaLb.font = [UIFont systemFontOfSize:12.0]; // * kScaleFit];
        _yue30songdaLb.textColor = [UIColor lightGrayColor];
        _yue30songdaLb.numberOfLines = 0;
    }
    return _yue30songdaLb;
}

//!!!!:预约点餐
- (UIView *)rightDiv {
    
    if (!_rightDiv) {
        _rightDiv = [[UIView alloc] init];
//        _rightDiv.backgroundColor = [UIColor redColor];
        UITapGestureRecognizer *rightTapges = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickRightTapGes)];
        [_rightDiv addGestureRecognizer:rightTapges];
    }
    return _rightDiv;
}
- (UILabel *)yuyuediancanLb {
    if (!_yuyuediancanLb) {
        _yuyuediancanLb = [[UILabel alloc] init];
        _yuyuediancanLb.text = NSLocalizedString(Home_Reservation, @"门店预约");
    }
    return _yuyuediancanLb;
}
- (UILabel *)bupaiduiLb {
    if (!_bupaiduiLb) {
        _bupaiduiLb = [[UILabel alloc] init];
        
        NSString *bpdstr = @"Rerseve A Table";
        if ([NSString rb_ChineseLanguage]) {
            bpdstr = @"预约取号不排队";
        }
        _bupaiduiLb.text = bpdstr;
        _bupaiduiLb.numberOfLines = 0;
        
        _bupaiduiLb.font = [UIFont systemFontOfSize:12.0 * kScaleFit];
        _bupaiduiLb.textColor = [UIColor lightGrayColor];
    }
    return _bupaiduiLb;
}

//!!!!:数组
- (NSMutableArray *)leftRightDivArrM {
    if (!_leftRightDivArrM) {
        _leftRightDivArrM = [NSMutableArray array];
    }
    return _leftRightDivArrM;
}
- (NSMutableArray *)leftViewArrayM {
    if (!_leftViewArrayM) {
        _leftViewArrayM = [NSMutableArray array];
    }
    return _leftViewArrayM;
}
- (NSMutableArray *)rightViewArrayM {
    if (!_rightViewArrayM) {
        _rightViewArrayM = [NSMutableArray array];
    }
    return _rightViewArrayM;
}

#pragma mark - 三 点击事件
- (void)clickLeftTapGes {
    FDLog(@"点击了左边的按钮%s--%d",__FUNCTION__,__LINE__);
    
    if (self.clickDinWeiBlock) {
        self.clickDinWeiBlock();
    }
}

- (void)clickRightTapGes {
    FDLog(@"点击了右边的按钮%s--%d",__FUNCTION__,__LINE__);
    if (self.clickYuYueBlock) {
        self.clickYuYueBlock();
    }
}
@end
